﻿using System;
using System.Drawing;
using System.Windows.Forms;
using ThoughtWorks.QRCode.Codec;


namespace 绘制二维码
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int picWidth = pictureBox1.Width;
            string str = textBox1.Text;
            //MessageBox.Show(picWidth.ToString());
            createQr(str);
        }

        private void createQr(string res)
        {
            QRCodeEncoder qr = new QRCodeEncoder();
            qr.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            qr.QRCodeScale = 8;
            qr.QRCodeVersion = 2;
            qr.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;

            //string str = "nihao";

            Bitmap bmp = null;
            bmp = qr.Encode(res);
            Graphics g = pictureBox1.CreateGraphics();
            g.DrawImage(bmp,0,0);
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
